# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test07
# Description:  例17.6
# Author:       ASUS
# Date:         2019/5/11
#-------------------------------------------------------------------------------


import threading
from time import sleep,ctime
#线程对象对应的类
class MyThread(object):
    def __init__(self,func,args):
        self.func = func
        self.args = args

    def __call__(self):
        self.func(*self.args)

#线程函数
def fun(index,sec):
    print('开始执行',index,'时间:',ctime())
    sleep(sec)
    print('结束执行',index,'时间：',ctime())
def main():
    print('开始执行时间:',ctime())
    #创建第一个线程
    thread1 = threading.Thread(target = MyThread(fun,(10,4)))
    thread1.start()
    thread2 = threading.Thread(target=MyThread(fun, (20, 2)))
    thread2.start()
    thread3 = threading.Thread(target=MyThread(fun, (30, 1)))
    thread3.start()
    #等待第一个线程函数执行完毕
    thread1.join()
    thread2.join()
    thread2.join()
    print('所有的线程函数已经执行完成：',ctime())
if __name__=='__main__':
    main()





